﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>项目基本信息维护</title>
    <link href="~/Scripts/jquery-easyui-1.4.4/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <link href="~/Content/formstyles.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "PMBasicMaintain", "KeyName": "PMBasicMaintain" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            var oldSelectRoleId;   //上次点选的RoleId
                            $("#ui_pm_dg").datagrid({       //初始化datagrid
                                url: "/Project/GetAllPMInfo?view=PMMaintain&r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                idField: 'ProjectID',
                                sort: 'UpdateTime',
                                order: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[
                                               {
                                                   hidden:true,
                                                   title: 'ID',
                                                   field: 'ProjectID'
                                               },
                                                 {
                                                     width: '100',
                                                     title: '项目编码',
                                                     field: 'ProjectNo',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 },
                                                 {
                                                     width: '120',
                                                     title: '项目名称',
                                                     field: 'ProjectName',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 }

                                ]],
                                columns: [[
                                     {
                                         field: 'status', title: '状态', sortable: false, width: 25,
                                         formatter: function (value, row, index) {
                                             return value==1 ? '<img src="../../Content/themes/icon/chk_checked.gif" alt="已确认" title="项目已确认" />' : '<img src="../../Content/themes/icon/chk_unchecked.gif" alt="未确认" title="项目未确认" />';
                                         }


                                     },
                                  { field: 'ProjectClerk', title: '业务员', sortable: false, width: 80, hidden: true },
                                { field: 'ProjectManager', title: '管理员', sortable: false, width: 80 },
                                 { field: 'UpdateBy', title: '最后更新人', width: 80 },
                                  { field: 'UpdateTime', title: '最后更新时间', sortable: true, width: 135 },                                          
                                    { field: 'CreateBy', title: '创建人',  width: 80 },
                                { field: 'CreateTime', title: '创建时间', sortable: true, width: 135 },
                                           {  field: 'Remark', title: '项目描述', width: 200,
                                               formatter: function (value, row, index) {
                                                   return value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                                               }
                                           }]],
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) {
                                    menuControl();
                                }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_pm_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_pm_searchdata();
                }
            })
        });
        //菜单标灰处理函数
        function menuControl() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要删除的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量删除");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }       
            if (rows[0].status == "" || rows[0].status == 0) {//未确认
                $(".icon-chk_checked").parent().parent().linkbutton("enable");
                $(".icon-chk_unchecked").parent().parent().linkbutton("disable");
            } else {//已确认
                $(".icon-chk_checked").parent().parent().linkbutton("disable");
                $(".icon-chk_unchecked").parent().parent().linkbutton("enable");
            }
        }

        //新增项目
        function AddPMBasicMaintain() {          
            $("<div/>").dialog({
                id: "ui_pm_add_dialog",
                href: "/Project/PMEdit",
                title: "新增项目",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        $.ajax({     //提交数据保存
                            url: "/Project/AddNewProject?r=" + Math.random(),
                            type: "post",
                            data: {
                                "KeyCode": "CreatePMBill", 
                                "ProjectID": $("#ProjectID").val(),
                                "ProjectNo": $("#ProjectNo").val(),
                                "ProjectName": $("#ProjectName").val(),
                                "ProjectManager": $("#ProjectManager").val(),
                                "ProjectClerk": $("#ProjectClerk").val(),
                                "Remark": $("#Remark").val()
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    $("#ui_pm_add_dialog").dialog('destroy');
                                    $("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_pm_add_dialog").dialog('destroy'); }
                }],
                onLoad: function () {                   
                    $("#ProjectNo").textbox('enable');
                    $("#ProjectName").textbox('enable');
                    $("#ProjectManager").textbox('enable');
                    $("#ProjectClerk").textbox('enable');
                    $("#Remark").textbox('enable');

                    $("#CreateBy").attr('hidden', 'hidden');
                    $("#CreateTime").attr('hidden', 'hidden');
                    $("#UpdateTime").attr('hidden', 'hidden');
                    $("#UpdateBy").attr('hidden', 'hidden');
                    $("#tt").attr('hidden', 'hidden');//隐藏节点管理

                },
                onClose: function () {
                    $("#ui_pm_add_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //修改项目
        function EditPMBasicMaintain() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row.length < 1) {
                $.show_alert("提示", "请先勾选要更新的项目");
                return;
            }
            if (row.length > 1) { 
                $.show_alert("提示", "不支持批量修改项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $("<div/>").dialog({
                id: "ui_pm_edit_dialog",
                href: "/Project/PMEdit",
                title: "更新项目",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar:[{
                    text:'保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        $.ajax({     //提交数据保存
                            url: "/Project/EditBasicProject?r=" + Math.random(),
                            type: "post",
                            data: {
                                "KeyCode": "EditPMBill",
                                "ProjectID": $("#ProjectID").val(),
                                "ProjectNo": $("#ProjectNo").val(),
                                "ProjectName": $("#ProjectName").val(),
                                "ProjectManager": $("#ProjectManager").val(),
                                "ProjectClerk": $("#ProjectClerk").val(),
                                "Remark": $("#Remark").val()
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    $("#ui_pm_edit_dialog").dialog('destroy');
                                    $("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })
                    } 
                },{
                    text:'关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_pm_edit_dialog").dialog('destroy'); }
                }],             
                onLoad: function () {
                    $("#ProjectID").val(row.ProjectID);
                    $("#ProjectNo").textbox('setValue',row.ProjectNo); 
                    $("#ProjectName").textbox('setValue',row.ProjectName); 
                    $("#ProjectManager").textbox('setValue',row.ProjectManager);                   
                    $("#ProjectClerk").textbox('setValue',row.ProjectClerk); 
                    $("#CreateBy").textbox('setValue',row.CreateBy); 
                    $("#CreateTime").textbox('setValue',row.CreateTime); 
                    $("#UpdateTime").textbox('setValue',row.UpdateTime);  
                    $("#UpdateBy").textbox('setValue',row.UpdateBy);  
                    $("#Remark").textbox('setValue', row.Remark);
                    $("#ProjectNo").textbox('enable');
                    $("#ProjectName").textbox('enable');
                    $("#ProjectManager").textbox('enable');
                    $("#ProjectClerk").textbox('enable');
                    $("#Remark").textbox('enable');

                    $("#tt").attr('hidden', 'hidden');//隐藏节点管理
                 
                },
                onClose: function () {
                    $("#ui_pm_edit_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
        //删除项目
        function DelPMBasicMaintain(){
            var rows = $("#ui_pm_dg").datagrid("getChecked");
                if (rows.length < 1) {
                    $.show_alert("提示", "请先勾选要删除的项目");
                    return;
                }
                if (rows.length > 1) {
                    $.show_alert("提示", "不支持批量删除");
                    $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                    return;
                }
                $.messager.confirm('提示', '确定删除：' + rows[0].ProjectName + '？', function (r) {
                    if (r) {                        
                        $.ajax({
                            url: "/Project/DelProjectByID?r=" + Math.random(),
                            data: {
                                ID: rows[0].ProjectID
                            },
                            type: "POST",
                            dataType: "json",
                            success: function (data) {
                                if (data.success) {
                                    $.show_alert("提示", data.msg);
                                    $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                    ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                    //if ($('#tabs').tabs('exists', '用户管理')) {
                                    //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                    //}
                                   
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            }
                        });
                    }
                });
            }

        //确认项目
        function confirmPMBasicMaintain() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要确认的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '确认该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm:"confirm"
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        //取消确认项目
        function unconfirmPMBasicMaintain() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要取消确认的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '取消确认该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm: "unconfirm"
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }

        function ui_pm_searchdata() {
            $("#ui_pm_dg").datagrid('load', {
                ProjectNo: $('#txtProjectNo').val(),
                ProjectName: $('#txtPMName').val(),
                status: $('#FStatus').val(),
                CreateTimeS: $('#txtAddBeginDate').datetimebox('getValue'),
                CreateTimeE: $('#txtAddEndDate').datetimebox('getValue')
            });
           // $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }

        function ui_pm_cleardata() { 
            $('#ui_pm_search input').val('');
            $('#ui_pm_search select').val('select');
            $('#txtAddBeginDate').datetimebox('setValue', '');
            $('#txtAddEndDate').datetimebox('setValue', '');
            $("#ui_pm_dg").datagrid('load', {});//清空条件自动加载数据

          //  $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
    </script>
        </head>
        <body>
            <div id="ui_pm_layout" class="easyui-layout" data-options="fit:true,border:false">
                <div data-options="region:'north',split:true,border:true,collapsed:true" title="条件搜索" style="height:104px;">
                    <div id="ui_pm_search">
                        <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                            <tr>
                                <th>
                                    项目编码：
                                </th>
                                <td>
                                    <input name="txtProjectNo" id="txtProjectNo" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                                </td>

                                <th>
                                    项目名称：
                                </th>
                                <td>
                                    <input name="txtPMName" id="txtPMName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                                </td>

                                <th>
                                    项目状态：
                                </th>
                                <td>
                                    <select name="FStatus" id="FStatus">
                                        <option value="select">请选择</option>
                                        <option value="0">未确认</option>
                                        <option value="1">已确认</option>
                                        <option value="2">已完成</option>
                                    </select>
                                </td>

                            <tr>
                                <th>
                                    添加时间：
                                </th>
                                <td>
                                    <input name="txtAddBeginDate" id="txtAddBeginDate" class="easyui-datetimebox"
                                           editable="false" style="width:150px;height:22px;" />
                                </td>

                                <th>
                                    至：
                                </th>
                                <td>
                                    <input name="txtAddEndDate" id="txtAddEndDate" class="easyui-datetimebox"
                                           editable="false" style="width:150px;height:22px;" />
                                </td>
                                <td colspan="4">
                                    <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                                       onclick="ui_pm_searchdata();">搜索</a>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                                       onclick="ui_pm_cleardata();">清空条件</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
<div data-options="region:'center',border:false">
    <table id="ui_pm_dg" data-options="fit:true,border:false"></table>
</div>
</div>
</body>
</html>
